
package com.forezp.exception;

import com.forezp.dto.RespDTO;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class CommonExceptionHandler {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@ExceptionHandler(CommonException.class)
	public ResponseEntity<RespDTO> handleException(Exception e) {
		RespDTO resp = new RespDTO();
		CommonException taiChiException = (CommonException) e;
		resp.code = taiChiException.getCode();
		resp.error = e.getMessage();
		return new ResponseEntity(resp, HttpStatus.OK);
	}
}